package com.vterm4aKafka.mapper;


import com.vterm4aKafka.domain.DeptInfo;
import com.vterm4aKafka.domain.FourAInfo;
import com.vterm4aKafka.domain.FourAInfoReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ program: elasticSearch_springBoot_study
 * @ description:
 * @ author: Mr.Zhongsf
 * @ create: 2021-03-18 10:17
 **/
@Mapper
public interface FourAInfoSearchMapper {
    @Select({
            "<script>",
            "SELECT * from",
            "four_a_details",
            "WHERE 1=1",

            "<when test='deptName!=null'>",
            "AND dept_name = #{deptName}",
            "</when>",

            "<when test='userNumber!=null'>",
            "AND user_number = #{userNumber}",
            "</when>",

            "<when test='userName!=null'>",
            "AND username = #{userName}",
            "</when>",

            "<when test='userId!=null'>",
            "AND userid = #{userId}",
            "</when>",


            "<when test='secDeptName!=null'>",
            "AND sec_dept_name = #{secDeptName}",
            "</when>",

            "<when test='beginTime!=null'>",
            "AND STR_TO_DATE(begintime,'%Y-%m-%d %H:%i:%s') &gt;= #{beginTime} ",
            "</when>",


            "<when test='endTime!=null'>",
            "AND STR_TO_DATE(begintime,'%Y-%m-%d %H:%i:%s') &lt;= #{endTime} ",
            "</when>",

            "ORDER BY",
            "<when test='sortMethod == 1'>",
            "begintime asc",
            "</when>",

            "<when test='sortMethod == 0'>",
            "onlineSecs asc",
            "</when>",

            "</script>"
    })
    @Results(value = {
            @Result(property = "deptName",column = "dept_name"),
            @Result(property = "secDeptName",column = "sec_dept_name"),
            @Result(property = "userNumber",column = "user_number"),
            @Result(property = "userId",column = "userid"),
            @Result(property = "userName",column = "username"),
            @Result(property = "userIp",column = "userip"),
            @Result(property = "resIp",column = "resip"),
            @Result(property = "beginTime",column = "begintime"),
            @Result(property = "endTime",column = "endtime"),
            @Result(property = "onlineSecs",column = "onlinesecs"),
            @Result(property = "resAccount",column = "resaccount"),
            @Result(property = "resName",column = "resname"),
            @Result(property = "sessionId",column = "sessionid"),
            @Result(property = "resGroupName",column = "resgroupname"),
            @Result(property = "resType",column = "restype"),
            @Result(property = "operTime",column = "opertime")
            }
    )
    public List<FourAInfo> selectFourAInfo(FourAInfoReq fourAInfoReq);



    //查找一级部门名deptName
    @Select("select * from kafka_dept where dgname = #{dgName}")
    @Results(value = {
            @Result(property = "deptName",column = "dept_name"),
            @Result(property = "dgName",column = "dgname"),
    })
    public List<DeptInfo> selectOrgInfo(FourAInfoReq fourAInfoReq);




}
